package com.sendtion.xrichtextdemo.db;

import com.sendtion.xrichtextdemo.utils.CommonUtil;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;

import ohos.app.Context;

import java.util.Date;

/**
 * MyOpenHelper
 *
 * @since 2021-06-22
 */
public class MyOpenHelper extends SQLiteOpenHelper {
    private static final String DB_NAME = "note.db";
    private static final int DB_VERSION = 1;

    /**
     * MyOpenHelper
     *
     * @param context
     */
    public MyOpenHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("create table db_group(g_id integer primary key autoincrement, "
                +
                "g_name varchar, g_order integer, g_color varchar, g_encrypt integer,"
                +
                "g_create_time datetime, g_update_time datetime )");
        sqLiteDatabase.execSQL("create table db_note(n_id integer primary key autoincrement, n_title varchar, "
                +
                "n_content varchar, n_group_id integer, n_group_name varchar, n_type integer, "
                +
                "n_bg_color varchar, n_encrypt integer, n_create_time datetime,"
                +
                "n_update_time datetime )");
        sqLiteDatabase.execSQL("insert into db_group(g_name, g_order, g_color,"
                +
                " g_encrypt, g_create_time, g_update_time) "
                +
                "values(?,?,?,?,?,?)", new String[]{"默认笔记", "1", "#FFFFFF", "0", CommonUtil.date2string(new Date()),
                CommonUtil.date2string(new Date())});
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
}
